package control;

import java.util.Date;
import java.util.HashMap;

import util.DateUtil;

import modelDB.Event;
import modelDB.Member;

import dao.EventDAO;
import dao.Manageable;
import dao.MemberDAO;

public class Test {
	public static void main(String[] args) {
		Test t = new Test();
		t.initDatabase();
	}
	
	public void initDatabase() {
		
		//BEGIN: Member
		MemberDAO memberDAO = new MemberDAO();
		Member m1 = new Member("KH01", "Thanh", "01234", DateUtil.createDate(15, 6, 1992), new Date());
		Member m2 = new Member("KH02", "Temp", "01235", DateUtil.createDate(1, 2, 1992), new Date());
		memberDAO.insert(m1);
		memberDAO.insert(m2);
		//END: Member
		
		//BEGIN: Event
		EventDAO eventDAO = new EventDAO();
		
		Event event1 = new Event();
		event1.setName("Noel");
		event1.setDescription("24/12 - Tang qua");
		event1.setStartDate(new Date());
		event1.setEndDate(new Date());
		event1.setDesignatedCusLv(0);
		HashMap<String, Double> map1 = new HashMap<String, Double>();
		map1.put("DT001", 10.0);
		map1.put("DT002", 10.0);
		map1.put("TO001", 20.5);
		event1.setDiscountProductMap(map1);
		
		Event event2 = new Event("Nha giao VN", "Tang nha giao", 0, DateUtil.createDate(18, 11, 2012), DateUtil.createDate(22, 11, 2012));
		HashMap<String, Double> map2 = new HashMap<String, Double>();
		map2.put("TO002", 10.5);
		map2.put("TO003", 11.0);
		map2.put("TO004", 5.5);
		event2.setDiscountProductMap(map2);
		
		eventDAO.insert(event1);
		eventDAO.insert(event2);
		
		//END: Event
		
		//Show added data
		printAll(memberDAO);
		printAll(eventDAO);
	}
	
	public <T, E> void printAll(Manageable<T, E> dao) {
		for (T t : dao.selectAll()) {
			System.out.println(t);
		}
	}
}
